#include "base.h"
#include <rtthread.h>

static struct rt_messagequeue mq;

static rt_ubase_t mq_buffer[8];

void sender_entry (void * param) {
    rt_ubase_t msg = 0;
    
    while (1) {
        rt_mq_send_wait(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER);
        msg++;
    }
}

void recv_entry (void * param) {
    while (1) {
        // recv
        rt_ubase_t msg;
        
        rt_mq_recv(&mq, &msg, sizeof(msg), RT_WAITING_FOREVER);
        rt_kprintf("recv: %d\n", msg);
        rt_thread_mdelay(1000);
    }
}

int main(void) {
    hardware_init();
    
    rt_mq_init(&mq, "mq", mq_buffer, sizeof(rt_ubase_t), 8, RT_IPC_FLAG_FIFO);
    
    rt_thread_t t1 = rt_thread_create("t1", sender_entry, RT_NULL, 4096, 10, 10);
    rt_thread_startup(t1);
    rt_thread_t t2 = rt_thread_create("t2", recv_entry, RT_NULL, 4096, 10, 10);
    rt_thread_startup(t2);
    
    return 0;
}
